/**
 * 通过黑名单 过滤query参数
 *
 * 例:  ?name=张三&age=18
 * blackList = ['age']
 * 返回: ?name=张三
 */

import { startsWith } from 'lodash';

const blackList = ['sign'];
function filterQuery(query) {
  // 如果遇到仪表盘查询参数,则直接返回原查询语句
  if (startsWith(query, 'exact')) {
    return query;
  }

  // 否则从黑名单中过滤某个query参数
  const params = new URLSearchParams(query);
  const objQuery = {};

  params.forEach((value, key) => {
    if (!blackList.includes(key)) {
      objQuery[key] = value;
    }
  });

  let originalStr = new URLSearchParams(objQuery).toString();
  originalStr = decodeURIComponent(originalStr).replace(/^\?/, '');

  return originalStr;
}

export default filterQuery;
